package list;

public class LeetCode86 {
    public ListNode partition(ListNode head, int x) {
        ListNode big = new ListNode(-1);
        ListNode small = new ListNode(-1);

        ListNode p = head;
        ListNode b = big;
        ListNode s = small;
        while (p != null) {
            if (p.val < x) {
                s.next = p;
                s = s.next;
            } else {
                b.next = p;
                b = b.next;
            }
            p = p.next;
        }
        b.next = null;
        s.next = big.next;
        return small.next;
    }
}
